﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Squog_1._1.Managers;

namespace Squog_1._1.Menu
{
    class PauseWindow : Window
    {
        private const int width = 540;
        private const int height = 360;

        private Texture2D DNA;
        private int DNArow = 0;
        private bool dir = true;
        private int TimePass;
        private int TimeToPass = 100;

        private Texture2D Cursor;
        private Texture2D Px;
        private int SelectedOption;

        private const int NumOptions = 2;
        private const int TextSpacing = 30;
        private Vector2 TextLocation = new Vector2((Settings.SafeZone.Left + (Settings.SafeZone.Width / 2)) - 100, Settings.SafeZone.Bottom - 240);


        public PauseWindow()
            : base(new Vector2(0.5f,0.5f), new Vector2(0,0))
        {
            DNA = DrawManager.Content.Load<Texture2D>(@"dna");
            Background = DrawManager.Content.Load<Texture2D>(@"pauseMenu");

            Cursor = DrawManager.Content.Load<Texture2D>(@"Menu\Cursor");
            Px = DrawManager.Content.Load<Texture2D>(@"Menu\px");

            SelectedOption = 0;
        }

        public override void LoadContent(ContentManager Content)
        {
            base.LoadContent(Content);
        }

        public override void Update(GameTime gameTime)
        {
            if (InputManager.OnPress(Thumbsticks.Left, 0, Direction.Up))
                SelectedOption--;
            if (InputManager.OnPress(Thumbsticks.Left, 0, Direction.Down))
                SelectedOption++;

            SelectedOption += NumOptions; //To handle a negitive number
            SelectedOption = SelectedOption % NumOptions; //To loop through the options


            if (InputManager.OnPress(Buttons.Start, 0))
            {
                //TODO: Unpause
                WindowManager.RemoveWindow();
            }

            TimePass += gameTime.ElapsedGameTime.Milliseconds;
            if (TimePass > TimeToPass)
            {
                TimePass -= TimeToPass;
                if (dir)
                {
                    DNArow++;
                    if (DNArow >= 6)
                        dir = !dir;
                }
                else
                {
                    DNArow--;
                    if (DNArow <= 0)
                        dir = !dir;
                }
            }

            if (InputManager.OnPress(Buttons.A, 0))
            {
                switch (SelectedOption)
                {
                    case 0:

                        //Game1.Squog.Equip(Abilities.Teleport);
                        break;
                    case 1:
                        //Game1.Squog.Equip(Abilities.Speed);
                        break;
                    //case 2:
                    //    Game1.Squog.Equip(Abilities.Flash);
                    //    break;
                }
            }

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            //Rectangle Window = new Rectangle(0, 0, Settings.SafeZone.Width * 2, Settings.SafeZone.Height * 2);
            //Game1.drawManager.spriteBatch.Draw(Px, Window, new Color(0.33f, 0.33f, 0.33f, 0.2f));

            //Game1.drawManager.spriteBatch.Draw(Cursor, TextLocation + new Vector2(-10, 14 + (SelectedOption * TextSpacing)), Color.Black);

            //Vector2 NextTextLoc = TextLocation;
            //if (Game1.Squog.EquipedAbility == Abilities.Teleport)
            //    Game1.drawManager.spriteBatch.DrawString(menuFont, "Telport (TT)", NextTextLoc, Color.Red);
            //else
            //    Game1.drawManager.spriteBatch.DrawString(menuFont, "Telport (TT)", NextTextLoc, Color.Black);

            //NextTextLoc.Y += TextSpacing;
            //if (Game1.Squog.EquipedAbility == Abilities.Speed)
            //    Game1.drawManager.spriteBatch.DrawString(menuFont, "Speed (SS)", NextTextLoc, Color.Red);
            //else
            //    Game1.drawManager.spriteBatch.DrawString(menuFont, "Speed (SS)", NextTextLoc, Color.Black);

            ////NextTextLoc.Y += TextSpacing;
            ////if (Game1.Squog.EquipedAbility == Abilities.Teleport)
            ////    Game1.drawManager.spriteBatch.DrawString(menuFont, "Telport (TT)", NextTextLoc, Color.Black);
            ////else
            ////    Game1.drawManager.spriteBatch.DrawString(menuFont, "Telport (TT)", NextTextLoc, Color.Black);

            ////Game1.drawManager.spriteBatch.DrawString(menuFont, "Speed (SS)", NextTextLoc, Color.Black);
            ////NextTextLoc.Y += TextSpacing;
            ////Game1.drawManager.spriteBatch.DrawString(menuFont, "Flash (ST)", NextTextLoc, Color.Black);


            //Game1.drawManager.spriteBatch.DrawString(menuFont, "DNA Collected: T(" + Game1.Squog.DNATeleport + ")  S(" + Game1.Squog.DNAFast + ")", new Vector2(BGRectangle.X + 5, BGRectangle.Y + BGRectangle.Height - 30), Color.Black);


            //Game1.drawManager.spriteBatch.Draw(DNA, new Vector2((WindowManager.WindowWidth / 2) - (width / 2) + 10, (WindowManager.WindowHeight / 2) - (height / 2) + 100), new Rectangle(178 * DNArow, 0, 178, 1008), Color.White, 0, Vector2.Zero, 0.2f, SpriteEffects.None, 0);
        }
    }
}
